//
//  MainViewController.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2021/12/10.
//

#import "MainViewController.h"
#import "ZCBaseNavigationController.h"
#import "GameRootViewController.h"
#import "InformationRootViewController.h"
#import "FuliRootViewController.h"
#import "Mine_RootViewController.h"
#import "CheckAppleOpenApi.h"

#import "HomeRootViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (@available(iOS 13.0, *)) {
        UITabBarAppearance * appearance = [[UITabBarAppearance alloc] init];
         // 背景色
        appearance.backgroundColor = [UIColor whiteColor];
        self.tabBar.standardAppearance = appearance;
        if (@available(iOS 15.0, *)) {
            self.tabBar.scrollEdgeAppearance = appearance;
        }
    }
    [self configViewControllers];
    
//    [self requestApple];
}

- (void)configViewControllers
{
    // 首页
    HomeRootViewController *home_rootVC = [HomeRootViewController new];
    ZCBaseNavigationController *home_nav = [[ZCBaseNavigationController alloc] initWithRootViewController:home_rootVC];
    home_nav.tabBarItem.title = @"首页";
    home_nav.tabBarItem.image = [[UIImage imageNamed:@"tabbar_home_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    home_nav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_home_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 分类
    GameRootViewController *game_rootVC = [GameRootViewController new];
    ZCBaseNavigationController *game_nav = [[ZCBaseNavigationController alloc] initWithRootViewController:game_rootVC];
    game_nav.tabBarItem.title = @"分类";
    game_nav.tabBarItem.image = [[UIImage imageNamed:@"tabbar_category_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    game_nav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_category_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 我的游戏
    InformationRootViewController *information_rootVC = [InformationRootViewController new];
    ZCBaseNavigationController *information_nav = [[ZCBaseNavigationController alloc] initWithRootViewController:information_rootVC];
    information_nav.tabBarItem.title = @"我的游戏";
    information_nav.tabBarItem.image = [[UIImage imageNamed:@"tabbar_game_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    information_nav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_game_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 福利中心
    FuliRootViewController *fuli_rootVC = [FuliRootViewController new];
    ZCBaseNavigationController *fuli_nav = [[ZCBaseNavigationController alloc] initWithRootViewController:fuli_rootVC];
    fuli_nav.tabBarItem.title = @"福利中心";
    fuli_nav.tabBarItem.image = [[UIImage imageNamed:@"tabbar_fuli_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    fuli_nav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_fuli_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 我的
    Mine_RootViewController *me_rootVC = [Mine_RootViewController new];
    ZCBaseNavigationController *me_nav = [[ZCBaseNavigationController alloc] initWithRootViewController:me_rootVC];
    me_nav.tabBarItem.title = @"我的";
    me_nav.tabBarItem.image = [[UIImage imageNamed:@"tabbar_mine_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    me_nav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_mine_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    if ([AppLogic sharedInstance].isApple) {
        self.viewControllers = @[home_nav, game_nav, information_nav, fuli_nav, me_nav];
    } else {
        self.viewControllers = @[home_nav, game_nav, information_nav, fuli_nav, me_nav];
    }
    
    self.tabBar.tintColor = kThemeTitleColor;
}

- (void)requestApple {
    CheckAppleOpenApi *api = [[CheckAppleOpenApi alloc] init];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        if (api.success) {
            NSString *appleStatus = [NSString stringWithFormat:@"%@", api.res];
            [AppLogic sharedInstance].isApple = appleStatus.boolValue;

            // 重置vc
            if(![AppLogic sharedInstance].isApple){
                [self configViewControllers];
            }
        }
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        
    }];
}

@end
